import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    userInfo: {}, // 用户信息
    openid: null, // 微信openid
    session_key: '', // 微信session_key
    client: null, // mqtt客户端
    FiendsApply: [], // 好友申请
    userid: '', // 用户id
    score: 0, // 用户分数
    roomid: '', // 房间号
    rivalid: '', // 对手id
    rivalInfo: {}, // 对手信息
    roomMessage: null, // 房间信息，用于重连
    result: {}, // 结算信息
    resultScore: 0, // 最终得分
    token: null,
    subject: null
  },
  mutations: {
    addFriendApply (state, value) {
      state.FriendsApply.push(value)
    },
    changeUserInfo (state, value) {
      state.userInfo = value
    },
    changeOpenid (state, value) {
      state.openid = value
    },
    changeSession_key (state, value) {
      state.session_key = value
    },
    changeClient (state, value) {
      state.client = value
    },
    changeUserid (state, value) {
      state.userid = value
    },
    changeScore (state, value) {
      state.score = value
    },
    changeRoomid (state, value) {
      state.roomid = value
    },
    changeRivalid (state, value) {
      state.rivalid = value
    },
    changeRoomMessage (state, value) {
      state.roomMessage = value
    },
    changeRivalInfo (state, value) {
      state.subject = null
      state.roomMessage = null
      state.rivalInfo = value
    },
    changeResult (state, value) {
      state.result = value
    },
    changeResultScore (state, value) {
      state.resultScore = value
    },
    resetRivalInfo (state, value) {
      state.rivalInfo = null
      state.roomMessage = null
    },
    resetRoomMessage (state, value) {
      state.roomMessage = null
    },
    changeToken (state, value) {
      state.token = value
    },
    changeSubject (state, value) {
      state.subject = {
        title: value.title,
        option: value.option
      }
    }
  },
  getters: {},
  actions: {}
})
export default store
